package ioc

// ComponentOption 配置组件选项的函数模型
type ComponentOption func(component *Component)

// WithComponentName 组件名
func WithComponentName(name string) ComponentOption {
	return func(c *Component) {
		c.setName(name)
	}
}

// Component 组件
type Component struct {
	name string // 组件名

	Value any // 组件实例 bean
}

func (c *Component) Name() string {
	return c.name
}

// 组件创建后，不允许外部逻辑修改组件名
func (c *Component) setName(n string) {
	c.name = n
}

func NewComponent(val any, opts ...ComponentOption) *Component {
	component := &Component{
		Value: val,
	}

	for _, o := range opts {
		o(component)
	}
	return component
}
